package com.example.transaction;

import com.alibaba.dubbo.config.annotation.Reference;
import com.example.service.ServiceApi;
import lombok.extern.slf4j.Slf4j;
import org.mengyun.tcctransaction.api.Compensable;
import org.mengyun.tcctransaction.dubbo.context.DubboTransactionContextEditor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;


/**
 * @ClassName Consume
 * @Description TODO
 * @Author zhaoluowei
 * @Date 2019/9/8  12:55
 * @Version 1.0
 */
@Component
@Slf4j
public class TransactionConsume {

    //    @Reference(interfaceClass = ServiceApi.class)
//    @Autowired
//    @Qualifier("transactionConsume")
    @Autowired
    private ServiceApi serviceApi;

    @Compensable(confirmMethod = "confirmSendMsg", cancelMethod = "cancelSendMsg", asyncCancel = true)
    public void sendMessage(String message) throws Exception {
//        System.out.println("TransactionConsume - this is consumer sendMessage message = " + message);
//        System.out.println(serviceApi.sendMsg(message));

        //模拟调用 创建订单的业务方法
        serviceApi.saveOrder("001",message,"6");
        serviceApi.isTrueSeats(message);
        serviceApi.isNotSold(message);


    }


    public void confirmSendMsg(String message) {
        System.out.println("TransactionConsume - this is consumer confirmSendMsg message = " + message);
//        System.out.println(serviceApi.sendMsg(message));
    }


    public void cancelSendMsg(String message) {
        System.out.println("TransactionConsume - this is consumer cancelSendMsg message = " + message);
//        System.out.println(serviceApi.sendMsg(message));
    }


}
